package com.eva.framework.common.spring;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

import java.beans.Introspector;

/**
 * Spring Bean名称生成器，用于处理同名类名注入
 */
public class UniqueNameGenerator extends AnnotationBeanNameGenerator {

    /**
     * 优先从注解中读取BeanName，读取不到时调用该方法生成BeanName
     *
     * @param definition BeanDefinition
     * @return String
     */
    @Override
    protected String buildDefaultBeanName(BeanDefinition definition) {
        String beanClassName = definition.getBeanClassName();
        Assert.state(beanClassName != null, "No bean class name set");
        return definition.getBeanClassName();
    }

}
